package com.ultrawise.survey.common.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.propertyeditors.CustomDateEditor;

public class DateEditor extends CustomDateEditor{
	public DateEditor(DateFormat dateFormat, boolean allowEmpty) {
		super(dateFormat, allowEmpty);
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 
		if(!StringUtils.isEmpty(text))
		{
			try {
				Date date = dateFormat.parse(text);
			} catch (ParseException e) {
				text = text+" "+"00:00:00";
			}
		}
		super.setAsText(text);
	}
}
